package nowcoder.ali;

import java.util.*;

public class NumMatch {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        HashMap<String, Integer> map = new HashMap<>();
        int[][] features = new int[n][k-1];
        int count = 0;
        for(int i=0;i<n;i++){
            int base = sc.nextInt();
            StringBuilder sbKey = new StringBuilder();
            StringBuilder matchKey = new StringBuilder();
            for(int j=1;j<k;j++){
                int cur = sc.nextInt();
                features[i][j-1] = cur - base;
                sbKey.append(features[i][j-1]);
                sbKey.append(",");
                matchKey.append(-features[i][j-1]);
                matchKey.append(",");
            }
            count += map.getOrDefault(matchKey.toString(),0);
            String key = sbKey.toString();
            map.put(key,map.getOrDefault(key,0)+1);
        }
        System.out.println(count);
    }
}